<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>侦听器</title>
</head>
<body>
  <div id="app">
    <input type="text" v-model="age">
    <h2>{{msg}}</h2>
  </div>
  <script src="vue.js"></script>
  <script>
    const vm = new Vue({
      el:"#app",
      data:{
        age:0,
        msg:""
      },
      watch:{
        //侦听age是否发生变化
        age(newVal,oldVal) {
          console.log(oldVal,newVal);
          if(newVal>=18) {
            this.msg = "已经成年"
          } else {
            this.msg = "未成年"
          }
        }
      }
    })
  </script>
</body>
</html>